package com.qf.electronic.mall.register.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qf.constant.RabbitConstant;
import com.qf.dto.ResultBean;
import com.qf.register.api.IRegisterService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("register")
public class RegisterController {

    @Reference
    private IRegisterService registerService;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    //手机号注册
    //发送验证码
    @RequestMapping("getCode")
    @ResponseBody
    public ResultBean getCode(String phone){
        rabbitTemplate.convertAndSend(RabbitConstant.SMS_TOPIC_EXCHANGE,"sms.send",phone);
        return ResultBean.ok();
    }
    //实现注册
    @RequestMapping("doRegister")
    @ResponseBody
    public ResultBean doRegister(String phone,String code,String password){
        return registerService.registerByphone(phone,code,password);
    }

    //邮箱注册
    @RequestMapping("registerByEmail")
    public String registerByEmail(String email,String password){
        ResultBean resultBean = registerService.registerByEmail(email, password);
        return "redirect:/login/showLogin";

    }

}
